/*******************************************************************
 *
 * Copyright (C), 2021-2022, Letstrong, All rights reserved.
 *
 * Author      : 
 * Create Time : 2021-01-04
 * Version     : v0.1
 * Description : 
 *******************************************************************/
 
/*----------------------------Head file----------------------------*/
#include "rwip_config.h"     		// SW configuration
#include "user_config.h"

#if(ROPE_CENTRAL_SUP_ENABLE)

#include <string.h>
#include "app.h"                     // Application Definitions
#include "app_task.h"                // application task definitions
#include "central.h"
#include "app_central.h"                // BLPS Application Module Definitions
#include "central_task.h"               // health thermometer functions
#include "gattc_task.h"
#include "co_bt.h"
#include "co_math.h"
#include "co_utils.h"
#include "arch.h"                    // Platform Definitions
#include "prf.h"
#include "user.h"
#include "ke_timer.h"
#include "prf_types.h"               // Profile common types definition

/*----------------------------macro file---------------------------*/

/*----------------------------type define--------------------------*/

/*----------------------------var define---------------------------*/
struct central_env_tag app_central_env;

/*-------------------------func declaration------------------------*/

/*-----------------------------------------------------------------*/

void app_central_init(void)
{
    // Reset the environment
    memset(&app_central_env, 0, sizeof(struct central_env_tag));
}

void app_central_add_sensor(void)
{
	struct central_db_cfg *db_cfg;
    // Allocate the CENTRAL_CREATE_DB_REQ
    struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD,
                                                  TASK_GAPM, TASK_APP,
                                                  gapm_profile_task_add_cmd, sizeof(struct central_db_cfg));
    // Fill message
    req->operation   = GAPM_PROFILE_TASK_ADD;
    req->sec_lvl     = 0;
    req->prf_task_id = TASK_ID_CENTRAL;
    req->app_task    = TASK_APP;
    req->start_hdl   = 0;

	// Set parameters
	db_cfg = (struct central_db_cfg* )req->param;
	// Sending of notifications is supported
	db_cfg->features = 0;

    // Send the message
    ke_msg_send(req);
}

static int app_central_msg_dflt_handler(ke_msg_id_t const msgid,
                                     void const *param,
                                     ke_task_id_t const dest_id,
                                     ke_task_id_t const src_id)
{
    // Drop the message
    return (KE_MSG_CONSUMED);
}


/*
 * LOCAL VARIABLE DEFINITIONS
 ****************************************************************************************
 */

/// Default State handlers definition
const struct ke_msg_handler app_central_msg_handler_list[] =
{
    // Note: first message is latest message checked by kernel so default is put on top.
    {KE_MSG_DEFAULT_HANDLER,        (ke_msg_func_t)app_central_msg_dflt_handler},
};

const struct ke_state_handler app_central_table_handler =
    {&app_central_msg_handler_list[0], (sizeof(app_central_msg_handler_list)/sizeof(struct ke_msg_handler))};


#endif	//#if(ROPE_CENTRAL_SUP_ENABLE)

